use stencil_util::{FieldName, TypeName};

use super::{common::Typedef, TypeFamily};
use crate::field::{FieldOp, FieldShape};

/// Typedef for a container type in the target language.
#[derive(Clone, Debug)]
pub struct NativeTypeTd {
    name: TypeName,

    /// The index in this list is the `FieldRef` that gets generated.
    fields: Vec<NativeTypeTdField>,
}

impl NativeTypeTd {
    pub fn fields(&self) -> &[NativeTypeTdField] {
        &self.fields
    }
}

impl Typedef for NativeTypeTd {
    fn name(&self) -> &TypeName {
        &self.name
    }

    fn family(&self) -> TypeFamily {
        TypeFamily::General
    }
}

#[derive(Clone, Debug)]
pub struct NativeTypeTdField {
    name: FieldName,
    shape: FieldShape,

    /// Operations we want to expose for this field.
    ops: Vec<FieldOp>,
}

impl NativeTypeTdField {
    pub fn name(&self) -> &FieldName {
        &self.name
    }

    pub fn shape(&self) -> &FieldShape {
        &self.shape
    }

    pub fn ops(&self) -> &[FieldOp] {
        &self.ops
    }
}
